<?php


namespace app\index\controller;


use app\common\model\Admin;
use app\common\model\attendDid;
use app\common\model\attendResult;
use app\common\model\Department;
use app\common\model\DepartmentAdmin;

class Select
{
    private $attendDidModel; // 临时部门表
    private $departmentModel; // 部门表
    private $adminModel; // 员工表
    private $departmentAdminModel; // 次级部门表
    private $attResultModel; // 考情结果表
    public function __construct()
    {
        $this->attendDidModel = new attendDid();
        $this->departmentModel = new Department();
        $this->adminModel = new Admin();
        $this->departmentAdminModel = new DepartmentAdmin();
        $this->attResultModel = new attendResult();
    }
    public function index(){

//        $Info = $this->adminModel->where('id',811)->find();

//        $Info = $this->departmentAdminModel->whereIn('department_id',[211,213])->select(); // 多个条件

//        $Info = $this->attResultModel->where('id',98503)->field('id,person_name,person_code,dept_name')->find();

//        $Info = $this->attResultModel->order('create_time DESC')->limit(10)->select();

//        $Info = $this->attResultModel->whereIn('person_name',['陈丽霞','陈林明'])->order('id desc')->select();

//        SELECT a.name,a.did,d.title FROM `oa_admin` AS a JOIN `oa_department` as d WHERE a.did = d.id AND name = '邓碧威';

//        $Info = $this->adminModel->alias('a')  // 设置oa_admin表的别名
//        ->join('oa_department d', 'a.did = d.id')  // 设置JOIN条件
//        ->where('a.name', '邓碧威')  // 设置WHERE条件
//        ->field('a.name, a.did, d.title')  // 指定需要查询的字段
//        ->select();  // 执行查询并返回结果

        // 查询员工的主部门和次要部门
        $Info = $this->adminModel->alias('a')
            ->join('oa_department d', 'd.id = a.did')
            ->join('oa_department_admin da','a.id = da.admin_id')
            ->join('oa_department de','da.department_id = de.id')
            ->field('a.name,a.did,d.title,da.department_id,de.title as dd_title')
            ->select();

        return json(['status' => 'success', 'message' => '操作成功', 'data' => $Info])->code(200);
    }

    // 查询OA没有的员工
    public function isAdmin(){

        // 查询OA员工
        $adminList = $this->adminModel->column('name');

        // 查询在职员工
        $didList = $this->attendDidModel->column('person_name');

        // 使用 array_diff 查找在 $array1 中但不在 $array2 中的人名
//        $diff1 = array_diff($adminList, $didList);

        // 使用 array_diff 查找在 $array2 中但不在 $array1 中的人名
        $diff2 = array_diff($didList, $adminList);

        // 合并两个结果，得到不同的人名
//        $diff = array_merge($diff1, $diff2);

        return json(['status' => 'success', 'message' => '操作成功', 'data' => $diff2])->code(200);
    }
}